﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="create-event.aspx.cs" Inherits="famails.BackEnd.page.create_event" MasterPageFile="~/Master.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <style type="text/css">
        .heartbeat {
            display: none;
            margin: 5px;
            color: blue;
        }
    </style>
    <%--<script language="javascript" type="text/javascript">
        $(function () {
            //setInterval(KeepSessionAlive, 10000);
        });

        function KeepSessionAlive() {
            $.post("/backend/page/KeepSessionAlive.ashx", null, function () {
                //$("#result").append("<p>Session is alive and kicking!<p/>");
                setInterval(function () { beatHeart(5); }, 10000);
            });
        }
        function beatHeart(times) {
            var interval = setInterval(function () {
                $(".heartbeat").fadeIn(500, function () {
                    $(".heartbeat").fadeOut(500);
                });
            }, 1000); // beat every second

            // after n times, let's clear the interval (adding 100ms of safe gap)
            setTimeout(function () { clearInterval(interval); }, (2000 * times) + 500);
        }

    </script>--%>
    <script type="text/javascript">
        function templateChange() {
            var contentId = $('select#<%=drlContent.ClientID%> option:selected').val();
            var Content = document.getElementById("ContentPlaceHolder1_drlContent");
            var subject = Content.options[Content.selectedIndex].text;
            document.getElementById("ContentPlaceHolder1_txtSubject").value = subject;
            $.ajax({
                type: "POST",
                url: "send-register.aspx/getContentTemplate",
                data: '{contentId: "' + contentId + '" }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: templateChangeSuccess,
                failure: function (response) {
                    alert("Không tồn tại mẫu này !");
                }
            });
        }

        function templateChangeSuccess(response) {
            if (response.d != null) {
                CKEDITOR.instances.ContentPlaceHolder1_txtBody.setData(response.d);
                var contentId = $('select#<%=drlContent.ClientID%> option:selected').val();
                var hiddenContentID = document.getElementById("ContentPlaceHolder1_hdfContentID");
                hiddenContentID.value = contentId;
            }
        }
        function signatureChange() {
            var SignId = $('select#<%=drlSign.ClientID%> option:selected').val();
            $.ajax({
                type: "POST",
                url: "send-register.aspx/getSign",
                data: '{SignId: "' + SignId + '" }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: signatureChangeSuccess,
                failure: function (response) {
                    alert("Chữ ký không tồn tại!");
                }
            });
        }
        function signatureChangeSuccess(response) {
            var dataResponse = response.d;
            if (dataResponse != null) {
                var currentData = CKEDITOR.instances.ContentPlaceHolder1_txtBody.getData();
                var displayData = currentData + "</br>" + dataResponse;
                CKEDITOR.instances.ContentPlaceHolder1_txtBody.setData(displayData);
            }
        }
        function openNewWindow() {
            window.open("CreateContentMail.aspx?Id=0", "_blank",
            "toolbar=yes, scrollbars=yes, resizable=yes,top=100, left=100, width=1000, height=600");
        }
        function insertHello() {
            var firtHello = document.getElementById("ContentPlaceHolder1_txtWelcome");
            var lastHello = document.getElementById("ContentPlaceHolder1_txtAfterWelcome");
            var customerName = document.getElementById("ContentPlaceHolder1_rdoCustomerName");
            var Wellcome = firtHello.value + " " + "[khachhang]" + " " + lastHello.value;
            if (customerName.checked == true) {
                Wellcome;
            }
            else {
                Wellcome = firtHello.value + " " + "[email]" + " " + lastHello.value;
                alert(Wellcome);
            }
            var currentData = CKEDITOR.instances.ContentPlaceHolder1_txtBody.getData();
            var displayData = Wellcome + "</br>" + currentData;
            CKEDITOR.instances.ContentPlaceHolder1_txtBody.setData(displayData);
        }

        function contentUpdate() {
        }
    </script>

    <div style="width: 100%; padding: 10px;">

        <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="border: 1px solid #333; padding: 0px; margin-bottom: 10px;">
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="padding: 10px 20px; background: #000; color: #fff; font-size: 18px; font-weight: bold; position: relative;">
                Thiết lập thời gian gửi
            </div>
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px;">
                <asp:Panel Visible="false" ID="pnError" runat="server">
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12 error-box round">
                        <asp:Label ID="lblError" runat="server" Text=""></asp:Label>
                    </div>
                </asp:Panel>
                <asp:Panel Visible="false" ID="PanelHourError" runat="server">
                    <div class="error-box round">
                        <asp:Label ID="lblHourError" runat="server" Text=""></asp:Label>
                    </div>
                </asp:Panel>

                <asp:Panel Visible="false" ID="pnSuccess" runat="server">
                    <div class="col-md-12 col-xs-12 col-sm-12 confirmation-box round">
                        <asp:Label ID="lblSuccess" runat="server" Text=""></asp:Label>
                    </div>
                </asp:Panel>
                <asp:HiddenField ID="hdfEventId" runat="server" />
            </div>
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px;">
                <fieldset>
                    <asp:HiddenField ID="HiddenField1" runat="server" />
                    <label for="simple-input" style="font-weight: bolder; text-transform: none">
                        Tiêu đề</label>
                    <asp:TextBox ID="txtAutoName" runat="server"
                        CssClass="form-control" Style="border: 1px solid #333; border-radius: 0px;" ToolTip="Nhập tựa đề bài viết"></asp:TextBox>
                </fieldset>
            </div>
            <div class="col-md-6 col-xs-12 col-sm-12 col-lg-6" style="height: auto; padding: 10px;">
                <fieldset>
                    <label for="simple-input" style="font-weight: bolder; text-transform: none">
                        Chọn email gửi</label>
                    <asp:DropDownList ID="drlMailConfig" CssClass="form-control" Style="margin-bottom: 5px; border: 1px solid #333; border-radius: 0px;" runat="server">
                    </asp:DropDownList>
                    <div class="pull-right"><i><a style="color: #333; font-weight: bold; font-size: 12px;" href="#" onclick="open_link('SenderVerify.aspx');">Cấu hình email mới</a></i></div>
                </fieldset>
            </div>
            <div class="col-md-6 col-xs-12 col-sm-12 col-lg-6" style="height: auto; padding: 10px;">
                <fieldset>
                    <label for="simple-input" style="font-weight: bolder; text-transform: none">
                        Chọn nhóm email gửi kèm</label>
                    <asp:DropDownList ID="drlMailGroup" CssClass="form-control" Style="margin-bottom: 5px; border: 1px solid #333; border-radius: 0px;" runat="server">
                    </asp:DropDownList>
                    <div class="pull-right"><i><a style="color: #333; font-weight: bold; font-size: 12px;" href="#" onclick="open_link('group-mail.aspx');">Tạo nhóm email mới</a></i></div>
                </fieldset>
            </div>
            <style>
                #ContentPlaceHolder1_chkDefaultPage {
                    margin-right: 0px;
                    margin-top: 6px;
                }
            </style>
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: 10px; background: #333; padding: 0px; margin: 10px 0px;">
            </div>
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 0px;">
                <fieldset>
                    <asp:ScriptManager ID="ScriptManager1" runat="server">
                    </asp:ScriptManager>
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <div class="col-md-6 col-xs-12 col-sm-12 col-lg-6" style="height: auto; padding: 10px;">
                                <label for="simple-input">Trang thông báo đăng ký thành công </label>
                                <asp:TextBox ID="txtResponeUrl" Enabled="false" CssClass="form-control" Style="border: 1px solid #333; border-radius: 0px;"
                                    runat="server"></asp:TextBox>
                            </div>
                            <div class="col-md-6 col-xs-12 col-sm-12 col-lg-6" style="height: auto; padding: 40px 0px 10px 20px;">
                                <asp:CheckBox ID="chkDefaultPage" runat="server" Checked="true"
                                    OnCheckedChanged="chkDefaultPage_CheckedChanged" AutoPostBack="True" />
                                Sử dụng trang mặc định (<i><a style="color: #333; font-weight: bold; font-size: 12px;" href="event-register-success.aspx" target="_blank">Xem trang mặc định</a></i>)
                            </div>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </fieldset>
            </div>
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: 10px; background: #333; padding: 0px; margin: 10px 0px;">
            </div>

            <div class="col-md-6 col-xs-12 col-sm-12 col-lg-6" style="height: auto; padding: 10px;">
                <fieldset>
                    <label for="simple-input" style="font-weight: bolder; text-transform: none">
                        Chọn nội dung</label>
                    <asp:DropDownList ID="drlContent" CssClass="form-control" Style="border: 1px solid #333; border-radius: 0px;" runat="server"
                        AutoPostBack="false" onchange="templateChange()">
                    </asp:DropDownList>
                </fieldset>
            </div>
            <div class="col-md-6 col-xs-12 col-sm-12 col-lg-6" style="height: auto; padding: 10px;">
                <fieldset>
                    <label for="simple-input" style="font-weight: bolder; text-transform: none">
                        Chọn chữ ký</label>
                    <asp:DropDownList ID="drlSign" CssClass="form-control" Style="border: 1px solid #333; border-radius: 0px;" runat="server"
                        AutoPostBack="false" onchange="signatureChange()">
                    </asp:DropDownList>
                </fieldset>
            </div>
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 0px;">
                <div class="col-md-2 col-xs-12 col-sm-4 col-lg-2" style="height: auto; padding: 10px;">
                    <fieldset>
                        <asp:TextBox ID="txtWelcome" CssClass="form-control" Style="margin-bottom: 5px; border: 1px solid #333; border-radius: 0px;" runat="server"
                            ToolTip="Nhập lời chào cho bức thư!">Chào</asp:TextBox>
                    </fieldset>
                </div>
                <div class="col-md-2 col-xs-12 col-sm-4 col-lg-2" style="height: auto; padding: 16px;">
                    <fieldset>
                        <asp:RadioButton ID="rdoCustomerName" Checked="true" GroupName="groupWelcome" runat="server" />Tên
                            khách hàng
                    </fieldset>
                </div>
                <div class="col-md-2 col-xs-12 col-sm-4 col-lg-2" style="height: auto; padding: 16px;">
                    <fieldset>
                        <asp:RadioButton ID="rdoCustomerEmail" GroupName="groupWelcome" runat="server" />Email
                            khách hàng
                    </fieldset>
                </div>
                <div class="col-md-4 col-xs-10 col-sm-6 col-lg-4" style="height: auto; padding: 10px;">
                    <fieldset>
                        <asp:TextBox ID="txtAfterWelcome" CssClass="form-control" Style="margin-bottom: 5px; border: 1px solid #333; border-radius: 0px;"
                            runat="server">thân mến !</asp:TextBox>
                    </fieldset>
                </div>
                <div class="col-md-2 col-xs-2 col-sm-6 col-lg-2" style="height: auto; padding: 10px 10px 0px 0px;">
                    <fieldset>
                        <asp:Button Style="background: #333; color: #fff; text-align: center; padding: 6px 11px; border-radius: 0px; width: 100%; min-width: 32px; min-height: 32px" OnClick="insertHello()" class="btn">
                            <span class="fa fa-plus" style="float: left; font-size: 20px"></span><span class="hidden-xs">Thêm lời chào</span>
                        </asp:Button>
                    </fieldset>
                </div>
            </div>
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px;">
                <fieldset>
                    <asp:HiddenField ID="hdfContentID" runat="server" />

                    <label for="simple-input" style="font-weight: bolder; text-transform: none">
                        Tiêu đề nội dung</label>
                    <asp:TextBox ID="txtSubject" runat="server"
                        CssClass="form-control" Style="border: 1px solid #333; border-radius: 0px;" ToolTip="Nhập tiêu đề bức thư của bạn"></asp:TextBox>
                </fieldset>
            </div>
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px;">
                <fieldset>
                    <asp:TextBox ID="txtBody" class="ckeditor" Style="border: 1px solid #333; border-radius: 0px;" runat="server" TextMode="MultiLine" AutoPostBack="true"></asp:TextBox>
                </fieldset>
            </div>
            <div class="col-md-4 col-xs-12 col-sm-6 col-lg-4" style="height: auto; padding: 10px;">
                <fieldset>
                    <div style="float: left; background: #333; color: #fff; text-align: center; padding: 7px 15px; border-radius: 0px;">
                        <span class="fa fa-clock-o" style="margin-right:10px;"></span>Cấu hình thời gian gửi ( tính theo giờ )
                    </div>
                </fieldset>
            </div>
            <div class="col-md-4 col-xs-12 col-sm-6 col-lg-2" style="height: auto; padding: 10px;">
                <fieldset>
                    <asp:TextBox ID="txtOrderNo" runat="server" placeholder="Thứ tự gửi" CssClass="form-control" Style="border: 1px solid #333; border-radius: 0px;"></asp:TextBox>
                </fieldset>
            </div>
            <div class="col-md-4 col-xs-12 col-sm-6 col-lg-2" style="height: auto; padding: 10px;">
                <fieldset>
                    
                    <asp:TextBox ID="txtHour" placeholder="Thời gian gửi" runat="server" CssClass="form-control" Style="border: 1px solid #333; border-radius: 0px;"></asp:TextBox>
                </fieldset>
            </div>
            <div class="col-md-4 col-xs-12 col-sm-12 col-lg-4" style="height: auto; padding: 10px;">
                <fieldset>
                    <button id="adhjskd" runat="server" class="btn" style="float: left; margin-right: 10px; background: #333; color: #fff; text-align: center; padding: 6px 15px; border-radius: 0px;"
                        onserverclick="btnSaveContent_Click">
                        <i style="margin-right: 10px;" class="fa fa-save"></i>Thêm
                    </button>
                </fieldset>
            </div>
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="margin-top: 10px; padding: 10px 20px; background: #000; color: #fff; font-size: 18px; font-weight: bold; position: relative;">
                Danh sách nội dung đã cấu hình
            </div>
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px; margin-bottom: 30px;">
                <fieldset>
                    <div class=" table-responsive">
                        <asp:Label ID="lbl" runat="server" Text=""></asp:Label>
                        <asp:HiddenField ID="hdfContentIdEdit" runat="server" />
                        <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                            <thead>
                                <tr>
                                    <%--<th style="width: 80px; text-align: center">ID</th>--%>
                                    <th style="width: 80px; text-align: center">Thứ tự</th>
                                    <th>Tiêu đề</th>
                                    <th>Thời gian</th>
                                    <th style="width: 100px;">Tùy chỉnh</th>
                                </tr>
                            </thead>
                            <tbody>
                                <asp:Repeater ID="dlContentSendEvent" runat="server">
                                    <ItemTemplate>
                                        <tr>
                                            <%--<td style="text-align: center;">
                                                <asp:Label ID="lblID" runat="server" Text=""></asp:Label>
                                            </td>--%>
                                            <td style="text-align: center;">
                                                <asp:Label ID="lblNo" runat="server" Text=""></asp:Label>
                                            </td>
                                            <td>
                                                <asp:Label Style="color: #333; text-decoration: none;" ID="lbtContent" runat="server"></asp:Label>
                                            </td>
                                            <td>
                                                <asp:Label ID="lblHour" runat="server" Text=""></asp:Label>
                                            </td>
                                            <td style="text-align: center;">
                                                <asp:LinkButton Style="color: #333;" ID="lbtEdit" runat="server" Visible='<%#Eval("id")+""==""?false:true %>'
                                                    OnClick="lbtEdit_Click1" CommandArgument='<%#Eval("id") %>'>
                                        <span style="font-size:20px;margin-right:10px;" class="fa fa-pencil"></span>
                                                </asp:LinkButton>
                                                <asp:LinkButton Style="color: #333;" ID="lbtContentDelete" runat="server"
                                                    OnClientClick="return confirmDelete('Nếu tiếp tục dữ liệu sẽ bị xóa khỏi hệ thống ?')"
                                                    OnClick="lbtContentDelete_Click">
                                        <span style="font-size:20px;" class="fa fa-trash-o"></span>
                                                </asp:LinkButton>
                                            </td>
                                        </tr>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </tbody>
                        </table>
                    </div>
                </fieldset>
            </div>
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px;">
                <button runat="server" class="btn col-md-2 col-xs-6 col-sm-3 col-lg-2" style="float: left; border: 1px solid #fff; background: #333; color: #fff; text-align: center; padding: 6px 15px; border-radius: 0px;"
                    onserverclick="btnSaveContentAndEvent_Click">
                    <i style="margin-right: 10px;" class="fa fa-save"></i>Lưu Sự kiện
                </button>
                <button runat="server" class="btn col-md-2 col-xs-6 col-sm-3 col-lg-2" style="float: left; border: 1px solid #fff; background: #333; color: #fff; text-align: center; padding: 6px 15px; border-radius: 0px;"
                    onserverclick="btnCreateNew_Click">
                    <i style="margin-right: 10px;" class="fa fa-refresh"></i>Tạo mới
                </button>
                <button runat="server" class="btn col-md-4 col-xs-12 col-sm-6 col-lg-4" style="float: left; border: 1px solid #fff; background: #333; color: #fff; text-align: center; padding: 6px 15px; border-radius: 0px;"
                    onserverclick="btnGenerate_Click">
                    <i style="margin-right: 10px;" class="fa fa-code"></i>Phát sinh code HTML
                </button>
            </div>
            <%--<div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto;padding:10px;">
            <fieldset>    
                    <asp:DataList ID="dlEvent" runat="server">
                        <HeaderTemplate>
                        <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12" style="background:#333;padding:10px;color:#fff;font-weight:bold;">
                                <div class="col-md-2 col-lg-2 col-sm-6 col-xs-6" style="padding:5px;">
                                    Tiêu đề
                                </div>
                                <div class="col-md-2 col-lg-2 col-sm-3 col-xs-3" style="padding:5px;">
                                    Email gửi
                                </div>
                                <div class="col-md-2 col-lg-2 hidden-sm  hidden-xs" style="padding:5px;">
                                    Thời gian bắt đầu
                                </div>
                                <div class="col-md-2 col-lg-2 hidden-sm   hidden-xs" style="padding:5px;">
                                    Thời gian kết thúc
                                </div>
                                <div class="col-md-2 col-lg-2 col-sm-3  col-xs-3" style="padding:5px;">
                                    Voucher
                                </div>
                                <div class="col-md-2 col-lg-2 col-sm-3  col-xs-3" style="padding:5px;">
                                    Thao tác
                                </div>
                        </div>
                        </HeaderTemplate>                      
                        <ItemTemplate>          
                        <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12" style="background:#fff;padding:10px;border-bottom:1px solid #333;border-left:1px solid #333;border-right:1px solid #333;">
                                <div class="col-md-2 col-lg-2 col-sm-6 col-xs-6" style="padding:5px;">
                                        <asp:LinkButton ID="lbtSubject" runat="server"></asp:LinkButton>
                                </div>
                                <div class="col-md-2 col-lg-2 col-sm-3 col-xs-3" style="padding:5px;">
                                    <asp:Label ID="lblEmailGui" runat="server" Text="ConfigId"></asp:Label>
                                </div>
                                <div class="col-md-2 col-lg-2 hidden-sm  hidden-xs" style="padding:5px;">
                                    <asp:Label ID="lblStartDate" runat="server" Text="StartDate"></asp:Label>
                                </div>
                                <div class="col-md-2 col-lg-2 hidden-sm   hidden-xs" style="padding:5px;">
                                    <asp:Label ID="lblEndDate" runat="server" Text="EndDate"></asp:Label>
                                </div>
                                <div class="col-md-2 col-lg-2 col-sm-3  col-xs-3" style="padding:5px;">
                                    <asp:Label ID="lblVoucher" runat="server" Text="Voucher"></asp:Label>
                                </div>
                                <div class="col-md-2 col-lg-2 col-sm-3  col-xs-3" style="padding:5px;">
                                        <asp:LinkButton style="color:#333;" ID="lbtEdit" runat="server"
                                            OnClick="lbtEdit_Click">
                                            <span style="font-size:20px;" class="fa fa-cog"></span>
                                        </asp:LinkButton>

                                        <asp:LinkButton style="color:#333;" ID="lbtDelete" runat="server"
                                            OnClientClick="return confirmDelete('Nếu tiếp tục dữ liệu sẽ bị xóa khỏi hệ thống ?')"
                                            OnClick="lbtDelete_Click">
                                            <span style="font-size:20px;" class="fa fa-trash-o"></span>
                                        </asp:LinkButton>
                                </div>
                        </div>

                        </ItemTemplate>
                    </asp:DataList>
            </fieldset>
        </div>--%>
        </div>
    </div>
    <script>
        function open_link(a) {
            var myWindow = window.open(a, "", "width=1200, height=800,left=100,top=100");
        }
    </script>
    <%--<script type="text/javascript">
        $(function () {
            $('#ContentPlaceHolder1_txtStartDate').datetimepicker();
            $('#ContentPlaceHolder1_txtEndDate').datetimepicker();
        });
    </script>--%>
</asp:Content>

